home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / Amiga-E / E_v3.2a_extras / PdSrc / PubScreenNames.e < prev    next >
Text File  |  1992-09-02  |  5KB  |  165 lines

  1. /* PubScreenNames.e
  2.  * Prints the names (and some other attributes) of the Public Screens actually
  3.  * opened. Also, tests for the presence of a particular screen.
  4.  *
  5.  * Public Domain by Diego Caravana.
  6.  *
  7.  *
  8.  * Thanks to Wouter van Oortmerssen for his VERY GOOD work, hoping that he
  9.  * will continue to improve E language !
  10.  *
  11.  * Hey, consider to learn E !!!
  12.  *
  13.  */
  14.  
  15. /* TAB=4 */
  16.  
  17. OPT OSVERSION=37
  18.  
  19. /* Here is OBJECT we use for copying data inherent to Public Screen. Copying
  20.  * data is necessary because the locking of PubScreen List must be as short as
  21.  * possible (see Commodore Autodocs). This is due to the fact that the list
  22.  * cannot be modified (i.e. no public screen can be opened/closed) while it is
  23.  * locked by a task.
  24.  */
  25.  
  26. OBJECT mypubscreen
  27.     name, flags:INT, visitorcnt:INT, screen, task, next
  28. ENDOBJECT
  29.  
  30. MODULE 'intuition/screens', 'exec/lists', 'exec/nodes'
  31.  
  32. CONST ARGS_NUM=2
  33. ENUM  ARG_FULL, ARG_EXISTS
  34.  
  35. ENUM ERR_NONE=0, ERR_PUBLOCK, ERR_MEM, ERR_WRONGARGS, OK_FOUND, OK_NOTFOUND
  36.  
  37. DEF    localpslist:mypubscreen, strflags[25]:STRING, args[ARGS_NUM]:ARRAY OF LONG
  38.  
  39. RAISE ERR_MEM        IF String()=NIL,
  40.       ERR_PUBLOCK    IF LockPubScreenList()=NIL,
  41.       ERR_WRONGARGS IF ReadArgs()=NIL,
  42.       ERR_MEM        IF New()=NIL
  43.  
  44. PROC main() HANDLE
  45. DEF pslist:PTR TO lh, psnode:PTR TO ln, i=0, localpsnode:PTR TO mypubscreen,
  46.     pubscreen:PTR TO pubscreennode, publock=NIL, rdargs=NIL
  47.  
  48.     VOID '$VER: PubScreenNames 1.1 (13.02.93) by Diego Caravana'
  49.  
  50.     rdargs := ReadArgs('FULL/S,EXISTS/K', args, 0)
  51.  
  52.     /* get the Public Screen List; it will not change while we are reading
  53.      */
  54.     publock := LockPubScreenList()
  55.  
  56.     /* the first loop: copy all data we need as fast as possible
  57.      */
  58.     pslist := publock
  59.     psnode := pslist.head
  60.     localpsnode := localpslist
  61.  
  62.     WHILE psnode.succ <> NIL
  63.  
  64.         /* test if EXISTS a screen with a specified name
  65.          */
  66.         IF StrCmp(psnode.name, args[ARG_EXISTS], ALL) THEN Raise(OK_FOUND)
  67.  
  68.         /* allocate a estring dinamically to reduce memory usegand because
  69.          * STRINGs are not permitted (actually, I hope :) in OBJECTs
  70.          */
  71.         localpsnode.name:=String(StrLen(psnode.name)+2)
  72.         StrCopy(localpsnode.name, psnode.name, ALL)
  73.         IF args[ARG_FULL]=-1    /* copy only if needed */
  74.             pubscreen:=psnode
  75.             localpsnode.flags:=pubscreen.flags
  76.             localpsnode.visitorcnt:=pubscreen.visitorcount
  77.             localpsnode.task:=pubscreen.sigtask
  78.             localpsnode.screen:=pubscreen.screen
  79.         ENDIF
  80.  
  81.         /* allocate a OBJECT to contain the informations about the next
  82.          * screen
  83.          */
  84.         localpsnode.next:=New(SIZEOF mypubscreen)
  85.  
  86.         /* change the pointers to examine the chain
  87.          */
  88.         localpsnode:=localpsnode.next
  89.          psnode:=psnode.succ
  90.     ENDWHILE
  91.  
  92.     UnlockPubScreenList()
  93.     publock:=NIL    /* to know that we have released the lock */
  94.  
  95.     /* at this point, if a screen name was specified with EXISTS, it has not
  96.      * been found as a Public Screen in the previous loop, so we can  surely
  97.      * exit with a null return code
  98.      */
  99.     IF StrLen(args[ARG_EXISTS]) <> 0 THEN Raise(OK_NOTFOUND)
  100.  
  101.     /* print header with description of fields
  102.      */
  103.     IF args[ARG_FULL]=-1    /* print the right one! */
  104.         WriteF('\n N. Name               Visitors Screen     Task       Flags\n')
  105.         WriteF(  ' ---------------------------------------------------------------------------\n')
  106.     ELSE
  107.         WriteF('\n N. Name\n')
  108.         WriteF(  ' ----------------------\n')
  109.     ENDIF
  110.  
  111.     /* the second loop: print all the data
  112.      */
  113.     localpsnode:=localpslist
  114.     WHILE localpsnode.next <> NIL
  115.         i++
  116.  
  117.         IF args[ARG_FULL]=-1    /* choose the infos to print */
  118.  
  119.             /* not-so-simple code: the two flags are independent by one another
  120.              * and also we want a "|" (OR in C) put between them; then, there
  121.              * is a default string which is used when no flag is set
  122.              */
  123.             StrCopy(strflags,'<No Flags Set>',ALL)
  124.             IF localpsnode.flags AND SHANGHAI
  125.                 StrCopy(strflags,'SHANGHAI',ALL)
  126.                 IF localpsnode.flags AND POPPUBSCREEN
  127.                     StrAdd(strflags,'|POPPUBSCREEN',ALL)
  128.                 ENDIF
  129.             ELSE
  130.                 IF localpsnode.flags AND POPPUBSCREEN
  131.                     StrCopy(strflags,'POPPUBSCREEN',ALL)
  132.                 ENDIF
  133.             ENDIF
  134.  
  135.             WriteF(' \l\d[2] \l\s[18]    \l\d[3]   $\z\h[8]  $\z\h[8]  \l\s\n',
  136.                 i, localpsnode.name, localpsnode.visitorcnt,
  137.                 localpsnode.screen, localpsnode.task, strflags )
  138.         ELSE
  139.             WriteF(' \l\d[2] \l\s[18]\n', i, localpsnode.name)
  140.         ENDIF
  141.  
  142.         localpsnode:=localpsnode.next
  143.     ENDWHILE
  144.     WriteF('\n Found \d Public Screen(s)\n\n', i)
  145.  
  146.     Raise(ERR_NONE)
  147.  
  148. EXCEPT
  149.     IF publock THEN UnlockPubScreenList()
  150.     IF rdargs THEN FreeArgs(rdargs)
  151.  
  152.     SELECT exception
  153.         CASE ERR_NONE;
  154.         CASE OK_FOUND;        CleanUp(5)        /* if WARN will be true */
  155.         CASE OK_NOTFOUND;    CleanUp(0)
  156.         CASE ERR_PUBLOCK;    WriteF('*** cannot obtain PubScreen infos!\n')
  157.         CASE ERR_MEM;        WriteF('*** no memory!\n')
  158.         DEFAULT;            PrintFault(IoErr(), '*** Error')
  159.     ENDSELECT
  160.  
  161.     IF exception THEN CleanUp(10)
  162.     CleanUp(0)
  163.  
  164. ENDPROC
  165.